<?php
namespace app\mini\controller\v1\shop;

use app\common\library\MemberVo;
use app\common\logic\CarLogic;
use app\common\logic\CustomerLogic;
use app\common\logic\MaintainLogic;
use app\mini\controller\Common;
use think\Request;

class Customer extends Common
{

    public $CustomerLogic;
    public $MaintainLogic;

    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $this->CustomerLogic = new CustomerLogic();
        $this->MaintainLogic = new MaintainLogic();
    }

    /**
     * 客户列表
     * @return \think\response\Json
     */
    public function index()
    {
        $res = $this->exception(function () {
            return $this->CustomerLogic->index(MemberVo::instance()->getShopId(),request()->param('keyword'));
        });
        return $this->response($res);
    }


    /**
     * 客户信息
     * @return \think\response\Json
     */
    public function info()
    {
        $res = $this->exception(function () {
            return $this->CustomerLogic->info(MemberVo::instance()->getShopId(),request()->param('member_id'));
        });
        return $this->response($res);
    }

    /**
     * 切换车辆
     * @return \think\response\Json
     */
    public function car_exchange()
    {
        $res = $this->exception(function () {
            return $this->CustomerLogic->car_exchange(request()->param());
        });
        return $this->response($res);
    }

    /**
     * 客户订单服务记录
     * @return \think\response\Json
     */
    public function orders()
    {
        $res = $this->exception(function () {
            return $this->CustomerLogic->orders(request()->param());
        });
        return $this->response($res);
    }


    /**
     * 更多信息
     */
    public function more_info()
    {
        $res = $this->exception(function () {
            return $this->CustomerLogic->moreInfo(request()->param());
        });
        return $this->response($res);
    }

    /**
     * 保养记录
     */
    public function maintain()
    {
        $res = $this->exception(function () {
            $params = request()->param();
            $params['shop_id'] = MemberVo::instance()->getShopId();
            return $this->MaintainLogic->index($params);
        });
        return $this->response($res);
    }

    /**
     * 添加保养信息
     */
    public function add_maintain()
    {
        $res = $this->exception(function () {
            $params = request()->param();
            $params['shop_id'] = MemberVo::instance()->getShopId();
            return $this->MaintainLogic->add($params);
        });
        return $this->response($res);
    }

    /**
     * 保养信息详情
     */
    public function maintain_detail()
    {
        $res = $this->exception(function () {
            $params = request()->param();
            $params['shop_id'] = MemberVo::instance()->getShopId();
            return $this->MaintainLogic->detail($params);
        });
        return $this->response($res);
    }

    /**
     * 车辆图片更新 - 商家端视角
     * @return \think\response\Json
     */
    public function update_picture()
    {
        $res = $this->exception(function () {
            $carLogic = new CarLogic();
            return $carLogic->update_picture_shop(request()->param());
        });
        return $this->response($res);
    }


}